package cn.bklovezz.yixiantong.ram.controller;

import cn.bklovezz.yixiantong.ram.base.ReturnResult;
import cn.bklovezz.yixiantong.ram.dto.AdminLoginUser;
import cn.bklovezz.yixiantong.ram.dto.AdminRegisterLoginUser;
import cn.bklovezz.yixiantong.ram.pojo.RefreshInfo;
import cn.bklovezz.yixiantong.ram.entity.LoginUserModel;
import cn.bklovezz.yixiantong.ram.service.AdminUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api
@RequestMapping("/api/ram/admin-user")
@Slf4j
@RestController
public class AdminUserController {
  private final AdminUserService adminUserService;

  @Autowired
  public AdminUserController(AdminUserService adminUserService) {
    this.adminUserService = adminUserService;
  }

  @ApiOperation(value = "注册接口")
  @PostMapping("/register")
  public ReturnResult<LoginUserModel> register(@RequestBody() AdminRegisterLoginUser user) {
    return adminUserService.register(user);
  }

  @ApiOperation(value = "账户 + 密码登录")
  @PostMapping("/login")
  public ReturnResult<LoginUserModel> login(@RequestBody() AdminLoginUser user) {
    return adminUserService.login(user);
  }

  @ApiOperation(value = "检查用户是否处于登录状态")
  @PutMapping("/check-login/{token}")
  public ReturnResult<Boolean> checkLogin(@ApiParam("当前请求的 token") @PathVariable String token) {
    return adminUserService.checkUserStatus(token);
  }

  @ApiOperation(value = "刷新用户token")
  @PutMapping("/refresh-user-token/{token}")
  public ReturnResult<RefreshInfo<String>> refreshUserToken(@PathVariable String token) {
    return adminUserService.refreshUserToken(token);
  }

//  @ApiOperation(value = "删除用户(高危操作，请谨慎)")
//  @DeleteMapping("/delete-user/{username}")
//  public ReturnResult<Object> deleteUserByUsername(@PathVariable("username") String username) {
//    return adminUserService.deleteUserByUsername(username);
//  }
}
